package com.per.demobeetlsql.controller;

import com.per.demobeetlsql.datasource.DynamicDataSource;
import com.per.demobeetlsql.entity.Emp;
import com.per.demobeetlsql.entity.TTest;
import com.per.demobeetlsql.service.DataService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * @author Cheng
 * @date 2020/9/24 15:13
 */
@RestController
@RequestMapping("/data")
public class DataController {

    @Autowired
    private DataService dataService;

    @GetMapping("/getEmp")
    public List<Emp> getAllEmp(String datasource) {
        return dataService.getAllEmp(datasource);
    }

    @GetMapping("/getTest")
    public List<TTest> getAll(String datasource) {
        DynamicDataSource.getInstance().createDataSource("sqlserver",
                "com.microsoft.sqlserver.jdbc.SQLServerDriver",
                "jdbc:sqlserver://192.168.1.135:1433;database=test", "sa", "sa");
        return dataService.getAll(datasource);
    }
}
